package com.example.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.shop.entity.Product;
import com.example.shop.mapper.ProductMapper;
import com.example.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    public ProductMapper productMapper;

    @Override
    public List<Product> getProductList() {
        return productMapper.selectAllOnSaleProduct();
    }

    @Override
    public int addproduct(Product product) {
        return productMapper.insert(product);
    }

    @Override
    public Product getproductById(int productId) {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", productId);
        //上架状态
        queryWrapper.eq("status", 1);
        return productMapper.selectOne(queryWrapper);
    }

}
